//
// Created by fanghr on 17-12-23.
//

#ifndef PROJECT_IMU_TIME_H
#define PROJECT_IMU_TIME_H

#include "../../include.h"

class imu_time {
public:
    struct table_t {
        friend class boost::serialization::access;

        uint8_t year, month, day, hour, minute, second;
        uint16_t microsecond;

        template<class Archive>
        void serialize(Archive &ar, const unsigned int) {
            ar & year;
            ar & month;
            ar & day;
            ar & hour;
            ar & minute;
            ar & second;
            ar & microsecond;
        }
    };

private:
    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive &ar, const unsigned int) {
        ar & table;
    }

    table_t table;
public:
    imu_time() {}

    imu_time(boost::array<uint8_t, 9> raw) {
        table.year = raw.at(0);
        table.month = raw.at(1);
        table.day = raw.at(2);
        table.hour = raw.at(3);
        table.minute = raw.at(4);
        table.second = raw.at(5);
        table.microsecond = (uint16_t) (raw.at(7) << 8) | raw.at(6);
    }

    table_t get() {
        return table;
    }
};

#endif //PROJECT_IMU_TIME_H
